import React from 'react';
import { Route, IndexRoute } from 'react-router';

import App from './containers/app' //ui视图
import Home from './containers/home' //ui视图
import Login from './containers/login' //ui视图

//import { loginRequireAuth } from '../auth/loginAuth';

//无状态（stateless）组件，一个简单的容器，react-router 会根据 route
//规则匹配到的组件作为 `props.children` 传入
const Container = (props) => {
    return (
        <div>{props.children}</div>
    );
};

const routes = (state) => {
    //onEnter={loginRequireAuth}
    //需要登录的时候才会效验
    function loginRequireAuth(nextState, replace) {
        if(!state.login.isLogin){
            replace(`/login`);
        }
    }
    return (
        <Route path="/" component={App}>
            <IndexRoute component={Home}/>
            <Route path="/login" component={Login} />
        </Route>
    )
};
export default routes;